home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
comm
/
misc
/
avmnfaxsrc1_33.lha
/
timer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-25
|
2KB
|
84 lines
/* $Header: pd:zvmrcs/timer.c,v 1.1 1993/04/07 18:47:36 rvillari Exp $ */
/* Timer i/o routines */
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/tasks.h>
#include "timer_proto.h"
/* EXPORTS */
struct timerequest* tr = 0;
struct timerequest* tr2 = 0;
/* some timer routines that we need */
struct timerequest *PrepareTimer() {
/* return a pointer to a time request. If any problem, return NULL */
int error;
struct MsgPort *timerport;
struct timerequest *timerReq;
timerport = CreatePort(0,0);
if (timerport == 0)
goto bad;
timerReq = (struct timerequest *)CreateExtIO(timerport,sizeof(struct timerequest));
if (timerReq == 0)
goto bad;
error = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest*)timerReq, 0);
if (error != 0)
goto bad;
return(timerReq);
bad:
if (timerReq) {
timerport = timerReq->tr_node.io_Message.mn_ReplyPort;
if (timerport) DeletePort(timerport);
DeleteExtIO((struct IORequest*)timerReq);
}
return 0;
}
void StartTimer(struct timerequest* timeRequest, ULONG seconds, ULONG microseconds) {
timeRequest->tr_node.io_Command = TR_ADDREQUEST; /* add a new timer request */
timeRequest->tr_time.tv_secs = seconds; /* seconds */
timeRequest->tr_time.tv_micro = microseconds; /* microseconds */
SendIO((struct IORequest*) timeRequest ); /* post request to the timer */
}
ULONG TimerSignal(struct timerequest* timeRequest) {
ULONG thisSignal = (1L << timeRequest->tr_node.io_Message.mn_ReplyPort->mp_SigBit);
return thisSignal;
}
void EndTimer(struct timerequest* timeRequest) {
ULONG timerSignal = TimerSignal(timeRequest);
AbortIO((struct IORequest*)timeRequest);
WaitIO((struct IORequest*)timeRequest);
SetSignal(0L, timerSignal);
}
void DeleteTimer(struct timerequest* timeRequest) {
struct MsgPort *tp;
CloseDevice((struct IORequest*)timeRequest);
tp = timeRequest->tr_node.io_Message.mn_ReplyPort;
DeletePort(tp);
DeleteExtIO((struct IORequest*)timeRequest);
}